﻿using System;
using System.Net;
using System.Management;

namespace OnlineLicenseConsumer
{
    public class Consumer
    {
        public string Url = "http://y182319.51host.net/weibee.php?ID={0}";
        public int GetLeftTimes(string id)
        {
            var result = wc.DownloadString(string.Format(Url,id));
            int daysleft;
            bool valid = int.TryParse(result,out daysleft);
            return daysleft;
        }
        static WebClient wc = new WebClient();
        public void BeginGetLeftTimes(DownloadStringCompletedEventHandler handler, string id)
        {
            wc.DownloadStringCompleted += handler;
            wc.DownloadStringAsync(new Uri(string.Format(Url,id)));
        }
        public string Cpu
        {
            get
            {
                try
                {
                    using (ManagementClass mc = new ManagementClass("Win32_Processor"))
                    {
                        string strCpuID = null;
                        using (ManagementObjectCollection moc = mc.GetInstances())
                        {
                            foreach (ManagementObject mo in moc)
                            {
                                strCpuID = mo.Properties["ProcessorId"].Value.ToString();
                                break;
                            }
                        }
                        return strCpuID;
                    }
                }
                catch
                {
                    return "";
                }
            }
        }
        private string SofaUrl = "http://y182319.51host.net/sf.php?ID={0}";
        public int GetLeftSofaAmount()
        {
            var result = wc.DownloadString(string.Format(SofaUrl, Cpu));
            int amountsleft;
            bool valid = int.TryParse(result, out amountsleft);
            return amountsleft;
        }
    }
}
